﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.OleDb;
using System.IO;

namespace DiaryPlanner.Diary
{
    public partial class photo_panel : UserControl
    {
        
        String fileDir = "";//file directory
        pic_draw_add pic_draw_add_object;

        public photo_panel(pic_draw_add object_picOrdraw)
        {
            InitializeComponent();
            pic_draw_add_object = object_picOrdraw;
        }

        private void photo_add_btn_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png;)|*.jpg; *.jpeg; *.gif; *.bmp; *.png;";
            DialogResult d = openFileDialog1.ShowDialog();

            if (d != DialogResult.Cancel)
            {
                fileDir = openFileDialog1.FileName;
                
                newPhoto_view.Image = Image.FromFile(fileDir);

            }
        }

        private void cancel_photo_btn_Click(object sender, EventArgs e)
        {
            pic_draw_add_object.Close();
        }

        private void save_photo_btn_Click(object sender, EventArgs e)
        {
            //사진을 등록하지 않음
            if (fileDir == "")
            {
                return;
            }

            //AlbumPhoto ap = new AlbumPhoto();
            //사진 저장            
            //파일명
            String fname = " ";
            if(pic_draw_add_object.mod_or_new == 0){
                fname = "AP" + "_" + pic_draw_add_object.new_diary_object.all_date + Path.GetFileName(fileDir);
                pic_draw_add_object.new_diary_object.all_date = fname;
            }
            else if (pic_draw_add_object.mod_or_new == 1)
            {
                fname = "AP" + "_" + pic_draw_add_object.mod_diary_object.all_date + Path.GetFileName(fileDir);
                pic_draw_add_object.mod_diary_object.all_date = fname;
            }
            File.Copy(fileDir, Application.StartupPath + "/UserImage/" + UserProfile.Instance().userId + "/Picture_photo/" + fname);

            this.newPhoto_view.Image = Image.FromFile(Application.StartupPath + "/UserImage/" + UserProfile.Instance().userId + "/Picture_photo/" + fname);
            this.textBox1.Text = fname;

            /*ap.photoName = fname;
            //이미지
            ap.Size = new Size(100, 100);
            ap.Image = Image.FromFile(Application.StartupPath + "/UserImage/" + UserProfile.Instance().userId + "/Picture_photo/" +  fname);
            ap.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;*/

            //사진 등록
            pic_draw_add_object.Close();
        }
    }
}
